package com.kongwg.java;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @author kongwg
 * @create 2020-12-18 20:22
 */
public class InputStreamReaderTest {

    @Test
    public void test1() throws Exception{
        FileInputStream fis = new FileInputStream("dbcp.txt");

        InputStreamReader isr = new InputStreamReader(fis);

        char[] cbuf = new char[10];
        int len;
        while ((len = isr.read(cbuf)) != -1){
            System.out.print(cbuf);
        }
        isr.close();
    }



    @Test
    public void test2() throws Exception{
        FileInputStream fis = new FileInputStream("dbcp.txt");
        FileOutputStream fos = new FileOutputStream("dbcp_gbk.txt");

        InputStreamReader isr = new InputStreamReader(fis,"utf-8");
        OutputStreamWriter osw = new OutputStreamWriter(fos,"gbk");

        char[] cbuf = new char[10];
        int len;

        while ((len = isr.read(cbuf)) != -1){
            osw.write(cbuf,0,len);
        }
        osw.close();
        isr.close();
    }
}
